package com.lab.controller.teacher;

import com.lab.common.DailyPageResult;
import com.lab.common.Result;
import com.lab.dto.DailyPageQueryDTO;
import com.lab.service.DailyMemberProgressService;
import com.lab.vo.DailyProgressVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/teacher/daily/progress")
@Slf4j
@Api(tags = "<任淑志老师端>成员进度-日进度表")
public class teacherDailyMemberProgressController {

    @Autowired
    private DailyMemberProgressService dailyMemberProgressService;

    @GetMapping("/page")
    @ApiOperation("成员进度分页查询")
    public Result<DailyPageResult> page(DailyPageQueryDTO dailyPageQueryDTO) {
        log.info("成员进度分页查询，参数为：{}", dailyPageQueryDTO);
        // 修复服务调用和参数引用，使用正确的服务和参数
        DailyPageResult dailyPageResult = dailyMemberProgressService.pageQuery(dailyPageQueryDTO);
        return Result.success(dailyPageResult);
    }

    @GetMapping("/role/{roleType}")
    @ApiOperation("根据前端/后端查询日进度详情")
    public Result<List<DailyProgressVO>> getByRoleType(@PathVariable String roleType) {
        List<DailyProgressVO> voList = dailyMemberProgressService.getByRoleType(roleType);
        if (voList == null) {
            return Result.error("未找到角色类型（前端/后端）为" + roleType + "的进度记录");
        }
        System.out.println("传入的角色类型：" + roleType);
        return Result.success(voList); // 前端拿到数组形式的结果
    }


    @GetMapping("/member/{memberName}")
    @ApiOperation("根据成员名字查询日进度详情")
    public Result<List<DailyProgressVO>> getByMemberName(@PathVariable String memberName) {
        List<DailyProgressVO> voList = dailyMemberProgressService.getByMemberName(memberName);
        if (voList == null || voList.isEmpty()) {
            return Result.error("未找到成员名为\"" + memberName + "\"的进度记录");
        }
        System.out.println("传入的成员名字：" + memberName);
        return Result.success(voList); // 前端拿到数组形式的结果
    }

    @GetMapping("/progressdate/{progressDate}")
    @ApiOperation("根据进度日期查询日进度详情")
    public Result<List<DailyProgressVO>> getDailyByProgressDate(
            @PathVariable
            @DateTimeFormat(pattern = "yyyy-MM-dd") // 指定日期格式，与前端传入格式一致
            LocalDate progressDate) {
        // 调用Service层方法，根据进度日期查询
        List<DailyProgressVO> contentList = dailyMemberProgressService.getByProgressDate(progressDate);
        // 若查询结果为空，返回“数据不存在”提示
        if (contentList == null || contentList.isEmpty()) {
            return Result.error("未找到进度日期为\"" + progressDate + "\"的进度记录");
        }
        return Result.success(contentList);
    }

    // @PostMapping("/daily")
    //@ApiOperation("新增每日进度")
    //public Result<?> addDailyProgress(@RequestBody DailyProgressDTO dto) {
    //    dailyMemberProgressService.addDailyProgress(dto);
    //   return Result.success("新增成功");
    //}



}